﻿//排序
var packageordertempvalue = 0;

//内容是否显示
$(function () {
    $(".isshowspan").click(function () {
        var isShowSpanObj = $(this);
        var isShow = isShowSpanObj.attr("isshow");
        var alertMessage = "";
        var isShowUrl = "";
        if (isShow == "0") {
            alertMessage = "您确认要设置此新闻为显示状态吗？";
            isShowUrl = isShowSpanObj.attr("url") + "&state=1" + "&t=" + new Date();
        }
        else if (isShow == "1") {
            alertMessage = "您确认要取消此新闻显示吗？";
            isShowUrl = isShowSpanObj.attr("url") + "&state=0" + "&t=" + new Date();
        }
        $.jBox.confirm(alertMessage, "提示", function (v, h, f) {
            if (v == 'ok') {
                $.jBox.tip("正在设置...", 'loading');
                $.get(isShowUrl, function (data, textStatus) {
                    if (data != "0") {
                        if (isShow == "0") {
                            isShowSpanObj.html("是").attr("isshow", "1");
                        }
                        else if (isShow == "1") {
                            isShowSpanObj.html("否").attr("isshow", "0");
                        }
                        $.jBox.tip('设置成功！', 'success');
                    } else {
                        $.jBox.error('设置失败，请联系管理员！', '设置失败');
                    }
                });
            }
            else if (v == 'cancel') {
                // 取消
            }

            return true; //close
        });
    });

    //更新新闻是否置顶ChangeNews
    $(".istopspan").click(function () {
        var IsTopSpanObj = $(this);
        var IsTop = IsTopSpanObj.attr("istop");
        var alertMessage = "";
        var IsTopUrl = "";
        if (IsTop == "0") {
            alertMessage = "您确认要设置此新闻为置顶吗？";
            IsTopUrl = IsTopSpanObj.attr("url") + "&state=1" + "&t=" + new Date();
        }
        else if (IsTop == "1") {
            alertMessage = "您确认要取消此新闻置顶吗？";
            IsTopUrl = IsTopSpanObj.attr("url") + "&state=0" + "&t=" + new Date();
        }
        $.jBox.confirm(alertMessage, "提示", function (v, h, f) {
            if (v == 'ok') {
                $.jBox.tip("正在设置...", 'loading');
                $.get(IsTopUrl, function (data, textStatus) {
                    if (data != "0") {
                        if (IsTop == "0") {
                            IsTopSpanObj.html("是").attr("istop", "1");
                        }
                        else if (IsTop == "1") {
                            IsTopSpanObj.html("否").attr("istop", "0");
                        }
                        $.jBox.tip('设置成功！', 'success');
                    } else {
                        $.jBox.error('设置失败，请联系管理员！', '设置失败');
                    }
                });
            }
            else if (v == 'cancel') {
                // 取消
            }

            return true; //close
        });
    });

    //更新新闻是否置首ChangeNewsIsHome
    $(".ishomespan").click(function () {
        var IsHomeSpanObj = $(this);
        var IsHome = IsHomeSpanObj.attr("ishome");
        var alertMessage = "";
        var IsHomeUrl = "";
        if (IsHome == "0") {
            alertMessage = "您确认要设置此新闻为置首吗？";
            IsHomeUrl = IsHomeSpanObj.attr("url") + "&state=1" + "&t=" + new Date();
        }
        else if (IsHome == "1") {
            alertMessage = "您确认要取消此新闻置首吗？";
            IsHomeUrl = IsHomeSpanObj.attr("url") + "&state=0" + "&t=" + new Date();
        }
        $.jBox.confirm(alertMessage, "提示", function (v, h, f) {
            if (v == 'ok') {
                $.jBox.tip("正在设置...", 'loading');
                $.get(IsHomeUrl, function (data, textStatus) {
                    if (data != "0") {
                        if (IsHome == "0") {
                            IsHomeSpanObj.html("是").attr("ishome", "1");
                        }
                        else if (IsHome == "1") {
                            IsHomeSpanObj.html("否").attr("ishome", "0");
                        }
                        $.jBox.tip('设置成功！', 'success');
                    } else {
                        w
                        $.jBox.error('设置失败，请联系管理员！', '设置失败');
                    }
                });
            }
            else if (v == 'cancel') {
                // 取消
            }

            return true; //close
        });
    });

    //新闻排序
    var oldStockInputValue = 0;
    $(".stockinput").focus(function () {
        var stockInputObj = $(this);
        oldStockInputValue = stockInputObj.val();
        stockInputObj.val("");
        stockInputObj.prop("class", "selectedsortinput");
    });
    $(".stockinput").blur(function () {
        var stockInputObj = $(this);
        if (stockInputObj.val() == "") {
            stockInputObj.val(oldStockInputValue)
        }
        else {
            var reg = /^\d+$/;
            if (!reg.test(stockInputObj.val())) {
                stockInputObj.val(oldStockInputValue).prop("class", "selectedsortinput");
                alert("只能输入数字！")
                return;
            }
            else {
                if (oldStockInputValue != stockInputObj.val()) {
                    $.jBox.tip("正在更新...", 'loading');
                    $.get(stockInputObj.attr("url") + "&stockNumber=" + stockInputObj.val() + "&t=" + new Date(), function (data, textStatus) {
                        if (data != "0") {
                            $.jBox.tip('更新成功！', 'success');
                        } else {
                            stockInputObj.val(oldStockInputValue);
                            $.jBox.error('更新失败，请联系管理员！', '更新失败');
                        }
                    });
                }
            }
        }
        stockInputObj.prop("class", "unselectedsortinput");
    });

})